package com.qf.utils;

import com.qf.pojo.SysUserInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * created by 赵文韬 on 2022/3/18 23:07
 */
//因为要使用很多次从session中获去登录用户的操作，所以封装成了工具类
public class SecurityUtils {
    //写一个静态的获取SysUserInfo对象的方法
    public static SysUserInfo getLoginUser(){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            return (SysUserInfo) request.getSession().getAttribute("user");
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public static SysUserInfo getLoginWithTest(){
        SysUserInfo userInfo = new SysUserInfo();
        userInfo.setUsername("wangwu");
        return userInfo;
    }
}
